
/*-----------------------------------------------------------------------------\
|                          ChipCFlow Block2Code V2.0                           |
|                                                                              |
| Desenvolvedor: Felipe Simões Lage Gomes Duarte                               |
| Orientador: Prof. Dr. Jorge Luiz e Silva                                     |
|                                                                              |
| Main Project: ChipCflow                                                      |
| Período: Agosto de 2010 a Julho de 2011                                      |
| Codigo: Main.java                                                            |
| Versão da IDE: NetBeans IDE 6.9.1 (Build 201011082200)                       |
| Java: 1.6.0_21; Java HotSpot(TM) Client VM 17.0-b17                          |
| Sistema Operacional: Windows 7 versão 6.1 executando em x86; pt_BR (nb)      |
|                                                                              |
|             O presente trabalho foi realizado com apoio do CNPq              |
|   Conselho Nacional de Desenvolvimento Científico  e Tecnológico - Brasil    |
\-----------------------------------------------------------------------------*/
package view; //Nome do pacote de dados.

//declaraçao das classes importadas
import java.awt.*;
import components.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.awt.event.*;
import controler.Action;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.JPopupMenu.Separator;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;

public class Block2Code extends javax.swing.JFrame implements MouseListener, MouseMotionListener {

  /*----- DECLARAÇÃO DE ATRIBUTOS DA CLASSE -----*/
  private static Block2Code SINGLETON = null;//instancia do programa
  private Action act = null;
  private javax.swing.JScrollPane ScrollDesenho;
  private ArrayList<JComponent> panel;//canvas de desenho
  private File Arquivo;
  private int ePanel;//variavel que indica a Ação selecionada
  private Estado estado;//variavel que indica a Ação selecionada
  private DefaultMutableTreeNode root;
  private boolean saved;
  private static final int EPANEL_B2C = 1;
  private static final int EPANEL_VHDL = 2;
  private static SimpleDateFormat sdf;


  /*----- Construtor da classe Paint -----*/
  public Block2Code() {
    //estados inciais
    this.estado = Estado.NULL;
    this.ePanel = -1;

    sdf = new SimpleDateFormat("< dd/MM/yyyy hh:mm:ss > \n");
    root = new DefaultMutableTreeNode("root", true);
    getList(root, new File("./"));

    //Inicia componentes graficas.
    initComponents();
    this.setLocation(((Toolkit.getDefaultToolkit().getScreenSize().width / 2) - (this.getWidth() / 2)),
            ((Toolkit.getDefaultToolkit().getScreenSize().height / 2) - (this.getHeight() / 2)));

    //inclui acoes ao programa
    act = Action.getInstance();
    //coloca o programa maximizado
    this.setExtendedState(MAXIMIZED_BOTH);

    tree.setRootVisible(false);
    //Inicializa estado da interface grafica
    ativarBotoes(false);
    //inicializa o  menu popup
    this.popupMenuOperadores();
    //inicialização de variaveis
    panel = new ArrayList<JComponent>();
    Arquivo = null;
  }

  static public Block2Code getInstance() {
    if (SINGLETON == null) {
      SINGLETON = new Block2Code();
    }
    return SINGLETON;
  }

  /****************************  Getter & Setter  ****************************/
  /*********************  Metodos Manipualaçã6 do Mouse  *********************/
  public void mouseClicked(MouseEvent e) {
  }

  public void mousePressed(MouseEvent e) {
    //para o painel de modelagem
    if (ePanel == EPANEL_B2C) {
      int x = e.getX();//pega as coordenadas do mouse
      int y = e.getY();
      switch (estado) {
        case TEXTO:
          act.escrever(x, y);//escreve o texto
          atualizar();//atualiza
          break;
        case OPERADORES:
          act.criarOperador(x, y);//criar operador
          atualizar();
          break;
        case CONECTORES_LINHA_RETA:
          act.criarConector(x, y);
          atualizar();
          break;
        case CONECTORES_MAO_LIVRE:
          act.criarConector(x, y);
          atualizar();
          break;
        case APAGAR:
          act.remover(x, y);
          atualizar();
          break;
        case MOVER:
          act.find(x, y);
          break;
        case ROTACAO:
          break;
      }
    }
  }

  public void mouseDragged(MouseEvent e) {
    //para o painel de modelagem
    if (ePanel == EPANEL_B2C) {
      int x = e.getX();//pega as coordenadas do mouse
      int y = e.getY();
      switch (estado) {
        case OPERADORES:
          act.setOpAuxCoordenadas(x, y);
          break;
        case CONECTORES_LINHA_RETA:
          act.setConectAuxEnd(x, y);
          break;
        case CONECTORES_MAO_LIVRE:
          act.setConectAuxEnd(x, y);
          act.conectAuxAdd(x, y);
          break;
        case MOVER:
          act.mover(x, y);
          break;
        case ROTACAO:
          break;
      }
      atualizar();
    }
  }

  public void mouseReleased(MouseEvent e) {
    //para o painel de modelagem
    if (ePanel == EPANEL_B2C) {
      int x = e.getX();//pega as coordenadas do mouse
      int y = e.getY();
      switch (estado) {
        case OPERADORES:
          act.finalizarOperador(x, y);
          atualizar();
          break;
        case CONECTORES_LINHA_RETA:
          act.finalizarConector(x, y);
          atualizar();
          break;
        case CONECTORES_MAO_LIVRE:
          act.finalizarConector(x, y);
          atualizar();
          break;
        case MOVER:
          atualizar();
          break;
        case ROTACAO:
          atualizar();
          break;
      }
    }
  }

  public void mouseEntered(MouseEvent e) {
    //mudar o ponteiro do mouse
    if (ePanel == EPANEL_B2C) {
      switch (estado) {
        case OPERADORES:
          setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
          break;
        case CONECTORES_LINHA_RETA:
          setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
          break;
        case CONECTORES_MAO_LIVRE:
          setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
          break;
        case TEXTO:
          setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
          break;
        case MOVER:
          setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
          break;
        default:
          setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          break;
      }
    } else if (ePanel == EPANEL_VHDL) {
      setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    }
  }

  public void mouseExited(MouseEvent e) {
    //mudar o ponteiro do mouse
    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
  }

  public void mouseMoved(MouseEvent e) {
  }

  /************************  Metodos Proposito Geral  ************************/
  private void ativarBotoes(boolean flag) {
    BranchButton.setEnabled(flag);
    DeciderButton.setEnabled(flag);
    CopyButton.setEnabled(flag);
    NDMergeButton.setEnabled(flag);
    DMergeButton.setEnabled(flag);
    OperatorButton.setEnabled(flag);
    InButton.setEnabled(flag);
    OutButton.setEnabled(flag);
    ConectLInhaRetaButton.setEnabled(flag);
    ConectMaoLivreButton.setEnabled(flag);
    MoverButton.setEnabled(flag);
    ApagarButton.setEnabled(flag);
    RotacaoButton.setEnabled(flag);
    TextoButton.setEnabled(flag);
  }

  private void atualizar() {
    //ReloadTable();//atualiza a tabela de operadores e conectores
    repaint();//desenha
    saved = false;
  }

  private void fechar() {
    if (!saved) {//Verifica se o desenho atual foi alterado
      int O = JOptionPane.showConfirmDialog(this, "Deseja salvar o projeto atual?");
      if (O == JOptionPane.YES_OPTION) {
        saved = true;
        SaveFileMenuItemActionPerformed(null);
        System.exit(0);
      }
      if (O == JOptionPane.NO_OPTION) {
        System.exit(0);
      }
    } else if (JOptionPane.showConfirmDialog(this, "Deseja realmente sair?") == JOptionPane.YES_OPTION) {
      System.exit(0);
    }
  }

  @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      popupMenuOperadores = new javax.swing.JPopupMenu();
      jPanel2 = new javax.swing.JPanel();
      ApagarButton = new javax.swing.JButton();
      RotacaoButton = new javax.swing.JButton();
      OutButton = new javax.swing.JButton();
      OperatorButton = new javax.swing.JButton();
      InButton = new javax.swing.JButton();
      ConectLInhaRetaButton = new javax.swing.JButton();
      TextoButton = new javax.swing.JButton();
      CopyButton = new javax.swing.JButton();
      MoverButton = new javax.swing.JButton();
      DeciderButton = new javax.swing.JButton();
      DMergeButton = new javax.swing.JButton();
      ConectMaoLivreButton = new javax.swing.JButton();
      NDMergeButton = new javax.swing.JButton();
      BranchButton = new javax.swing.JButton();
      newOperadorButton = new javax.swing.JButton();
      jPanel3 = new javax.swing.JPanel();
      jScrollPane2 = new javax.swing.JScrollPane();
      tree = new javax.swing.JTree(root);
      mainTabbedPane = new JTabbedPaneWithCloseIcons();
      BarraMenu = new javax.swing.JMenuBar();
      MenuArquivo = new javax.swing.JMenu();
      jSeparator1 = new javax.swing.JSeparator();
      novoArquivoSubMenu = new javax.swing.JMenu();
      novoArquivoB2C = new javax.swing.JMenuItem();
      novoOperador = new javax.swing.JMenuItem();
      jSeparator3 = new javax.swing.JSeparator();
      LoadFileMenuItem = new javax.swing.JMenuItem();
      SaveFileMenuItem = new javax.swing.JMenuItem();
      SaveAsFileMenuItem = new javax.swing.JMenuItem();
      ExportarMenuItem = new javax.swing.JMenuItem();
      jSeparator2 = new javax.swing.JSeparator();
      FecharMenuItem = new javax.swing.JMenuItem();
      MenuFormatar = new javax.swing.JMenu();
      jSeparator4 = new javax.swing.JPopupMenu.Separator();
      FonteFormatMenuItem = new javax.swing.JMenuItem();
      jMenu2 = new javax.swing.JMenu();
      TraduzirMenuOption = new javax.swing.JMenuItem();
      MenuFerramentas = new javax.swing.JMenu();
      OpcoesMenuItem = new javax.swing.JMenuItem();
      MenuAjuda = new javax.swing.JMenu();
      AboutMenuItem = new javax.swing.JMenuItem();
      jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();

      popupMenuOperadores.setBorder(javax.swing.BorderFactory.createTitledBorder("Operadores"));
      popupMenuOperadores.setName("popupMenuOperadores"); // NOI18N

      setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
      setTitle("ChipCFlow Block2Code");
      setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
      setIconImage(new ImageIcon(Block2Code.class.getResource("/imagens/progicon.png")).getImage());
      setMinimumSize(new java.awt.Dimension(1000, 608));
      addWindowListener(new java.awt.event.WindowAdapter() {
         public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
         }
      });

      jPanel2.setName("jPanel2"); // NOI18N

      ApagarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/delete.png"))); // NOI18N
      ApagarButton.setMaximumSize(new java.awt.Dimension(24, 24));
      ApagarButton.setMinimumSize(new java.awt.Dimension(24, 24));
      ApagarButton.setName("ApagarButton"); // NOI18N
      ApagarButton.setPreferredSize(new java.awt.Dimension(24, 24));
      ApagarButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            ApagarButtonActionPerformed(evt);
         }
      });

      RotacaoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/rotate.png"))); // NOI18N
      RotacaoButton.setMaximumSize(new java.awt.Dimension(24, 24));
      RotacaoButton.setMinimumSize(new java.awt.Dimension(24, 24));
      RotacaoButton.setName("RotacaoButton"); // NOI18N
      RotacaoButton.setPreferredSize(new java.awt.Dimension(24, 24));
      RotacaoButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            RotacaoButtonActionPerformed(evt);
         }
      });

      OutButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Out.png"))); // NOI18N
      OutButton.setMaximumSize(new java.awt.Dimension(24, 24));
      OutButton.setMinimumSize(new java.awt.Dimension(24, 24));
      OutButton.setName("OutButton"); // NOI18N
      OutButton.setPreferredSize(new java.awt.Dimension(24, 24));
      OutButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            OutButtonActionPerformed(evt);
         }
      });

      OperatorButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Operator.png"))); // NOI18N
      OperatorButton.setMaximumSize(new java.awt.Dimension(24, 24));
      OperatorButton.setMinimumSize(new java.awt.Dimension(24, 24));
      OperatorButton.setName("OperatorButton"); // NOI18N
      OperatorButton.setPreferredSize(new java.awt.Dimension(24, 24));
      OperatorButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            OperatorButtonActionPerformed(evt);
         }
      });

      InButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/In.png"))); // NOI18N
      InButton.setMaximumSize(new java.awt.Dimension(24, 24));
      InButton.setMinimumSize(new java.awt.Dimension(24, 24));
      InButton.setName("InButton"); // NOI18N
      InButton.setPreferredSize(new java.awt.Dimension(24, 24));
      InButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            InButtonActionPerformed(evt);
         }
      });

      ConectLInhaRetaButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/line.png"))); // NOI18N
      ConectLInhaRetaButton.setMaximumSize(new java.awt.Dimension(24, 24));
      ConectLInhaRetaButton.setMinimumSize(new java.awt.Dimension(24, 24));
      ConectLInhaRetaButton.setName("ConectLInhaRetaButton"); // NOI18N
      ConectLInhaRetaButton.setPreferredSize(new java.awt.Dimension(24, 24));
      ConectLInhaRetaButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            ConectLInhaRetaButtonActionPerformed(evt);
         }
      });

      TextoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/texto.png"))); // NOI18N
      TextoButton.setMaximumSize(new java.awt.Dimension(24, 24));
      TextoButton.setMinimumSize(new java.awt.Dimension(24, 24));
      TextoButton.setName("TextoButton"); // NOI18N
      TextoButton.setPreferredSize(new java.awt.Dimension(24, 24));
      TextoButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            TextoButtonActionPerformed(evt);
         }
      });

      CopyButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Copy.png"))); // NOI18N
      CopyButton.setMaximumSize(new java.awt.Dimension(24, 24));
      CopyButton.setMinimumSize(new java.awt.Dimension(24, 24));
      CopyButton.setName("CopyButton"); // NOI18N
      CopyButton.setPreferredSize(new java.awt.Dimension(24, 24));
      CopyButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            CopyButtonActionPerformed(evt);
         }
      });

      MoverButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/move.png"))); // NOI18N
      MoverButton.setMaximumSize(new java.awt.Dimension(24, 24));
      MoverButton.setMinimumSize(new java.awt.Dimension(24, 24));
      MoverButton.setName("MoverButton"); // NOI18N
      MoverButton.setPreferredSize(new java.awt.Dimension(24, 24));
      MoverButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            MoverButtonActionPerformed(evt);
         }
      });

      DeciderButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Decider.png"))); // NOI18N
      DeciderButton.setMaximumSize(new java.awt.Dimension(24, 24));
      DeciderButton.setMinimumSize(new java.awt.Dimension(24, 24));
      DeciderButton.setName("DeciderButton"); // NOI18N
      DeciderButton.setPreferredSize(new java.awt.Dimension(24, 24));
      DeciderButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            DeciderButtonActionPerformed(evt);
         }
      });

      DMergeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/DMerge.png"))); // NOI18N
      DMergeButton.setMaximumSize(new java.awt.Dimension(24, 24));
      DMergeButton.setMinimumSize(new java.awt.Dimension(24, 24));
      DMergeButton.setName("DMergeButton"); // NOI18N
      DMergeButton.setPreferredSize(new java.awt.Dimension(24, 24));
      DMergeButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            DMergeButtonActionPerformed(evt);
         }
      });

      ConectMaoLivreButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/maoLivre.png"))); // NOI18N
      ConectMaoLivreButton.setMaximumSize(new java.awt.Dimension(24, 24));
      ConectMaoLivreButton.setMinimumSize(new java.awt.Dimension(24, 24));
      ConectMaoLivreButton.setName("ConectMaoLivreButton"); // NOI18N
      ConectMaoLivreButton.setPreferredSize(new java.awt.Dimension(24, 24));
      ConectMaoLivreButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            ConectMaoLivreButtonActionPerformed(evt);
         }
      });

      NDMergeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/NDMerge.png"))); // NOI18N
      NDMergeButton.setMaximumSize(new java.awt.Dimension(24, 24));
      NDMergeButton.setMinimumSize(new java.awt.Dimension(24, 24));
      NDMergeButton.setName("NDMergeButton"); // NOI18N
      NDMergeButton.setPreferredSize(new java.awt.Dimension(24, 24));
      NDMergeButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            NDMergeButtonActionPerformed(evt);
         }
      });

      BranchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Branch.png"))); // NOI18N
      BranchButton.setMaximumSize(new java.awt.Dimension(24, 24));
      BranchButton.setMinimumSize(new java.awt.Dimension(24, 24));
      BranchButton.setName("BranchButton"); // NOI18N
      BranchButton.setPreferredSize(new java.awt.Dimension(24, 24));
      BranchButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            BranchButtonActionPerformed(evt);
         }
      });

      newOperadorButton.setMaximumSize(new java.awt.Dimension(24, 24));
      newOperadorButton.setMinimumSize(new java.awt.Dimension(24, 24));
      newOperadorButton.setName("newOperadorButton"); // NOI18N
      newOperadorButton.setPreferredSize(new java.awt.Dimension(24, 24));
      newOperadorButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            newOperadorButtonActionPerformed(evt);
         }
      });

      javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
      jPanel2.setLayout(jPanel2Layout);
      jPanel2Layout.setHorizontalGroup(
         jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel2Layout.createSequentialGroup()
            .addComponent(BranchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(DeciderButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(CopyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(NDMergeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(DMergeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(OperatorButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(newOperadorButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(InButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(OutButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(ConectLInhaRetaButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(ConectMaoLivreButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(MoverButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(ApagarButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(RotacaoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(TextoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(114, Short.MAX_VALUE))
      );
      jPanel2Layout.setVerticalGroup(
         jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addComponent(BranchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(DeciderButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(CopyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(NDMergeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(DMergeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(OperatorButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(newOperadorButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(InButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(OutButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(ConectMaoLivreButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(ConectLInhaRetaButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(RotacaoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(ApagarButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(MoverButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addComponent(TextoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
      );

      jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
      jPanel3.setName("jPanel3"); // NOI18N
      jPanel3.setPreferredSize(new java.awt.Dimension(200, 489));

      jScrollPane2.setName("jScrollPane2"); // NOI18N

      tree.setName("tree"); // NOI18N
      jScrollPane2.setViewportView(tree);

      javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
      jPanel3.setLayout(jPanel3Layout);
      jPanel3Layout.setHorizontalGroup(
         jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
      );
      jPanel3Layout.setVerticalGroup(
         jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
      );

      mainTabbedPane.setName("mainTabbedPane"); // NOI18N
      mainTabbedPane.addChangeListener(new javax.swing.event.ChangeListener() {
         public void stateChanged(javax.swing.event.ChangeEvent evt) {
            mainTabbedPaneStateChanged(evt);
         }
      });

      BarraMenu.setName("BarraMenu"); // NOI18N

      MenuArquivo.setText("Arquivo");
      MenuArquivo.setName("MenuArquivo"); // NOI18N

      jSeparator1.setName("jSeparator1"); // NOI18N
      MenuArquivo.add(jSeparator1);

      novoArquivoSubMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/New_File.png"))); // NOI18N
      novoArquivoSubMenu.setText("Novo Arquivo");
      novoArquivoSubMenu.setName("novoArquivoSubMenu"); // NOI18N

      novoArquivoB2C.setText("Arquivo de Modelagem (*.b2c)");
      novoArquivoB2C.setName("novoArquivoB2C"); // NOI18N
      novoArquivoB2C.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            novoArquivoB2CActionPerformed(evt);
         }
      });
      novoArquivoSubMenu.add(novoArquivoB2C);

      novoOperador.setText("Operador com Arquivo Fonte existente(*.vhd)");
      novoOperador.setName("novoOperador"); // NOI18N
      novoOperador.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            novoOperadorActionPerformed(evt);
         }
      });
      novoArquivoSubMenu.add(novoOperador);

      MenuArquivo.add(novoArquivoSubMenu);

      jSeparator3.setName("jSeparator3"); // NOI18N
      MenuArquivo.add(jSeparator3);

      LoadFileMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Open_Folder.png"))); // NOI18N
      LoadFileMenuItem.setText("Abrir Arquivo...");
      LoadFileMenuItem.setName("LoadFileMenuItem"); // NOI18N
      LoadFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            LoadFileMenuItemActionPerformed(evt);
         }
      });
      MenuArquivo.add(LoadFileMenuItem);

      SaveFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
      SaveFileMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Save_File.png"))); // NOI18N
      SaveFileMenuItem.setText("Salvar");
      SaveFileMenuItem.setName("SaveFileMenuItem"); // NOI18N
      SaveFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            SaveFileMenuItemActionPerformed(evt);
         }
      });
      MenuArquivo.add(SaveFileMenuItem);

      SaveAsFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
      SaveAsFileMenuItem.setText("Salvar como...");
      SaveAsFileMenuItem.setName("SaveAsFileMenuItem"); // NOI18N
      SaveAsFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            SaveAsFileMenuItemActionPerformed(evt);
         }
      });
      MenuArquivo.add(SaveAsFileMenuItem);

      ExportarMenuItem.setText("Exportar");
      ExportarMenuItem.setName("ExportarMenuItem"); // NOI18N
      ExportarMenuItem.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            ExportarMenuItemActionPerformed(evt);
         }
      });
      MenuArquivo.add(ExportarMenuItem);

      jSeparator2.setName("jSeparator2"); // NOI18N
      MenuArquivo.add(jSeparator2);

      FecharMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
      FecharMenuItem.setText("Sair");
      FecharMenuItem.setName("FecharMenuItem"); // NOI18N
      FecharMenuItem.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            FecharMenuItemActionPerformed(evt);
         }
      });
      MenuArquivo.add(FecharMenuItem);

      BarraMenu.add(MenuArquivo);

      MenuFormatar.setText("Formatar");
      MenuFormatar.setName("MenuFormatar"); // NOI18N

      jSeparator4.setName("jSeparator4"); // NOI18N
      MenuFormatar.add(jSeparator4);

      FonteFormatMenuItem.setText("Fonte");
      FonteFormatMenuItem.setName("FonteFormatMenuItem"); // NOI18N
      FonteFormatMenuItem.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            FonteFormatMenuItemActionPerformed(evt);
         }
      });
      MenuFormatar.add(FonteFormatMenuItem);

      BarraMenu.add(MenuFormatar);

      jMenu2.setText("File");
      jMenu2.setName("jMenu2"); // NOI18N

      TraduzirMenuOption.setText("Traduzir / Compilar");
      TraduzirMenuOption.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            TraduzirMenuOptionActionPerformed1(evt);
         }
      });
      jMenu2.add(TraduzirMenuOption);

      BarraMenu.add(jMenu2);

      MenuFerramentas.setText("Ferramentas");
      MenuFerramentas.setName("MenuFerramentas"); // NOI18N

      OpcoesMenuItem.setText("Opções");
      OpcoesMenuItem.setName("OpcoesMenuItem"); // NOI18N
      OpcoesMenuItem.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            OpcoesMenuItemActionPerformed(evt);
         }
      });
      MenuFerramentas.add(OpcoesMenuItem);

      BarraMenu.add(MenuFerramentas);

      MenuAjuda.setText("Ajuda");
      MenuAjuda.setName("MenuAjuda"); // NOI18N

      AboutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
      AboutMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Sobre.png"))); // NOI18N
      AboutMenuItem.setText("Sobre...");
      AboutMenuItem.setName("AboutMenuItem"); // NOI18N
      AboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            AboutMenuItemActionPerformed(evt);
         }
      });
      MenuAjuda.add(AboutMenuItem);

      jCheckBoxMenuItem1.setSelected(true);
      jCheckBoxMenuItem1.setText("jCheckBoxMenuItem1");
      jCheckBoxMenuItem1.setName("jCheckBoxMenuItem1"); // NOI18N
      MenuAjuda.add(jCheckBoxMenuItem1);

      BarraMenu.add(MenuAjuda);

      setJMenuBar(BarraMenu);

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
               .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
               .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                  .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 772, Short.MAX_VALUE)))
            .addContainerGap())
      );
      layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(mainTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE)
               .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE))
            .addContainerGap())
      );

      pack();
   }// </editor-fold>//GEN-END:initComponents

    private void FecharMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FecharMenuItemActionPerformed
      fechar();
    }//GEN-LAST:event_FecharMenuItemActionPerformed

    private void AboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AboutMenuItemActionPerformed
      new Sobre().setVisible(true);
    }//GEN-LAST:event_AboutMenuItemActionPerformed

    private void LoadFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoadFileMenuItemActionPerformed
      JFileChooser JanelaArquivo = new JFileChooser();
      JanelaArquivo.setFileFilter(new FileNameExtensionFilter("Arquivo Codigo VHDL (*.vhd)", "vhd"));
      JanelaArquivo.setFileFilter(new FileNameExtensionFilter("Arquivo do ChipCFlow Block2Code (*.b2c)", "b2c"));
      if (JanelaArquivo.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
        return;
      }
      Arquivo = JanelaArquivo.getSelectedFile();

      if (Arquivo.getName().endsWith("vhd")) {
        String str;
        JTextPane textArea = new JTextPane();
        try {
          BufferedReader in = new BufferedReader(new FileReader(Arquivo.getAbsolutePath()));
          while ((str = in.readLine()) != null) {
            textArea.setText(textArea.getText() + str + "\n");
          }
        } catch (Exception erro) {
          erro.printStackTrace();
        }
        panel.add(textArea);
      } else if (Arquivo.getName().endsWith("b2c")) {
        ObjectInputStream obj_in = null;
        try {
          act.load(Arquivo);
          novoArquivoB2CActionPerformed(null);
          repaint();
        } catch (Exception e) {
          JOptionPane.showMessageDialog(null, e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
        }
      }

      mainTabbedPane.removeAll();
      for (int i = 0; i < act.getDataSize() - 1; i++) {
        novoPainelProjeto();
      }
      repaint();
    }//GEN-LAST:event_LoadFileMenuItemActionPerformed

    private void SaveFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveFileMenuItemActionPerformed
      if (Arquivo == null) {
        JFileChooser JanelaArquivo = new JFileChooser();
        JanelaArquivo.setFileFilter(new FileNameExtensionFilter("Arquivo do ChipCFlow Block2Code (*.b2c)", "b2c"));
        if (JanelaArquivo.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
          Arquivo = null;
          return;
        }
        Arquivo = JanelaArquivo.getSelectedFile();
      }
      try {//Tenta salvar os bytes no arquivo
        String ext = Arquivo.getName().substring(Arquivo.getName().lastIndexOf('.') + 1);
        if (ext.equals(Arquivo.getName())) {
          Arquivo = (new File(Arquivo.getAbsolutePath() + ".b2c"));
        }
        act.save(Arquivo);
      } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
      }
      saved = true;
    }//GEN-LAST:event_SaveFileMenuItemActionPerformed

    private void SaveAsFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveAsFileMenuItemActionPerformed
      File _arq = Arquivo;
      Arquivo = null;
      SaveFileMenuItemActionPerformed(null);
      if (Arquivo == null) {
        Arquivo = _arq;
      }
      saved = true;
    }//GEN-LAST:event_SaveAsFileMenuItemActionPerformed

    private void FonteFormatMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FonteFormatMenuItemActionPerformed
      Fonte.getInstance().setVisible(true);
    }//GEN-LAST:event_FonteFormatMenuItemActionPerformed

    private void OperatorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OperatorButtonActionPerformed
      act.setOpAux(new Op_Operator());
      estado = Estado.OPERADORES;
}//GEN-LAST:event_OperatorButtonActionPerformed

    private void DMergeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DMergeButtonActionPerformed
      act.setOpAux(new Op_DMerge());
      estado = Estado.OPERADORES;
}//GEN-LAST:event_DMergeButtonActionPerformed

    private void NDMergeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NDMergeButtonActionPerformed
      act.setOpAux(new Op_NDMerge());
      estado = Estado.OPERADORES;
}//GEN-LAST:event_NDMergeButtonActionPerformed

    private void DeciderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeciderButtonActionPerformed
      act.setOpAux(new Op_Decider());
      estado = Estado.OPERADORES;
}//GEN-LAST:event_DeciderButtonActionPerformed

    private void CopyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CopyButtonActionPerformed
      act.setOpAux(new Op_Copy());
      estado = Estado.OPERADORES;
}//GEN-LAST:event_CopyButtonActionPerformed

    private void BranchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BranchButtonActionPerformed
      act.setOpAux(new Op_Branch());
      estado = Estado.OPERADORES;
}//GEN-LAST:event_BranchButtonActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
      fechar();
    }//GEN-LAST:event_formWindowClosing

    private void TextoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TextoButtonActionPerformed
      estado = Estado.TEXTO;
    }//GEN-LAST:event_TextoButtonActionPerformed

    private void ConectLInhaRetaButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConectLInhaRetaButtonActionPerformed
      estado = Estado.CONECTORES_LINHA_RETA;
    }//GEN-LAST:event_ConectLInhaRetaButtonActionPerformed

    private void ConectMaoLivreButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConectMaoLivreButtonActionPerformed
      estado = Estado.CONECTORES_MAO_LIVRE;
    }//GEN-LAST:event_ConectMaoLivreButtonActionPerformed

    private void OpcoesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpcoesMenuItemActionPerformed
      Opcoes.getInstance().setVisible(true);
    }//GEN-LAST:event_OpcoesMenuItemActionPerformed

    private void InButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_InButtonActionPerformed
      act.setOpAux(new Op_In());
      estado = Estado.OPERADORES;
    }//GEN-LAST:event_InButtonActionPerformed

    private void OutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OutButtonActionPerformed
      act.setOpAux(new Op_Out());
      estado = Estado.OPERADORES;
    }//GEN-LAST:event_OutButtonActionPerformed

    private void MoverButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MoverButtonActionPerformed
      estado = Estado.MOVER;
    }//GEN-LAST:event_MoverButtonActionPerformed

    private void RotacaoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RotacaoButtonActionPerformed
      estado = Estado.ROTACAO;
    }//GEN-LAST:event_RotacaoButtonActionPerformed

    private void ApagarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ApagarButtonActionPerformed
      estado = Estado.APAGAR;
    }//GEN-LAST:event_ApagarButtonActionPerformed

    private void ExportarMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExportarMenuItemActionPerformed
      //Save.getInstance().SalvarImagem(false);
    }//GEN-LAST:event_ExportarMenuItemActionPerformed

    private void TraduzirMenuOptionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TraduzirMenuOptionActionPerformed
    }//GEN-LAST:event_TraduzirMenuOptionActionPerformed

    private void novoArquivoB2CActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novoArquivoB2CActionPerformed
      Action.newDados();
      novoPainelProjeto();
    }//GEN-LAST:event_novoArquivoB2CActionPerformed

  private void novoPainelProjeto() {
    ePanel = EPANEL_B2C;
    ativarBotoes(true);
    int CanvasLarg = 20000;
    int CanvasAlt = 20000;
    JComponent auxComponent = new Desenho();//alocação do painel de desenho
    auxComponent.setSize(new Dimension(CanvasLarg, CanvasAlt));
    auxComponent.setBackground(Color.white);//set cor de fundo
    auxComponent.addMouseListener(this);
    auxComponent.addMouseMotionListener(this);
    auxComponent.revalidate();
    addTabMainTabbedPane(auxComponent, "B2C");
  }

    private void novoOperadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novoOperadorActionPerformed
      //cria o primeiro item do menu e atribui uma ação pra ele
      JMenuItem item1 = new JMenuItem("Opção " + Integer.toString(this.ePanel));
      item1.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
        }
      });

      popupMenuOperadores.add(item1);
    }//GEN-LAST:event_novoOperadorActionPerformed

    private void mainTabbedPaneStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_mainTabbedPaneStateChanged
      act.setCurrentIndex(mainTabbedPane.getSelectedIndex());
      if (false) {
        ePanel = EPANEL_VHDL;
        ativarBotoes(false);
      } else {
        ativarBotoes(true);
        ePanel = EPANEL_B2C;
      }
    }//GEN-LAST:event_mainTabbedPaneStateChanged

    private void TraduzirMenuOptionActionPerformed1(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TraduzirMenuOptionActionPerformed1
      try {
        act.traduzir();
      } catch (Exception ex) {
        Logger.getLogger(Block2Code.class.getName()).log(Level.SEVERE, null, ex);
      }
    }//GEN-LAST:event_TraduzirMenuOptionActionPerformed1

    private void newOperadorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newOperadorButtonActionPerformed
      //mostra na tela
      popupMenuOperadores.show(newOperadorButton, 10, 10);
    }//GEN-LAST:event_newOperadorButtonActionPerformed

  private void addTabMainTabbedPane(JComponent auxComponent, String title) {
    ScrollDesenho = new javax.swing.JScrollPane(auxComponent);
    ScrollDesenho.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.background"));
    ScrollDesenho.setName("ScrollDesenho");
    ScrollDesenho.setPreferredSize(new java.awt.Dimension(250, 100));
    mainTabbedPane.addTab(title, ScrollDesenho);
    mainTabbedPane.setSelectedIndex(mainTabbedPane.getTabCount() - 1);
    panel.add(auxComponent);
  }
   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JMenuItem AboutMenuItem;
   private javax.swing.JButton ApagarButton;
   private javax.swing.JMenuBar BarraMenu;
   private javax.swing.JButton BranchButton;
   private javax.swing.JButton ConectLInhaRetaButton;
   private javax.swing.JButton ConectMaoLivreButton;
   private javax.swing.JButton CopyButton;
   private javax.swing.JButton DMergeButton;
   private javax.swing.JButton DeciderButton;
   private javax.swing.JMenuItem ExportarMenuItem;
   private javax.swing.JMenuItem FecharMenuItem;
   private javax.swing.JMenuItem FonteFormatMenuItem;
   private javax.swing.JButton InButton;
   private javax.swing.JMenuItem LoadFileMenuItem;
   private javax.swing.JMenu MenuAjuda;
   private javax.swing.JMenu MenuArquivo;
   private javax.swing.JMenu MenuFerramentas;
   private javax.swing.JMenu MenuFormatar;
   private javax.swing.JButton MoverButton;
   private javax.swing.JButton NDMergeButton;
   private javax.swing.JMenuItem OpcoesMenuItem;
   private javax.swing.JButton OperatorButton;
   private javax.swing.JButton OutButton;
   private javax.swing.JButton RotacaoButton;
   private javax.swing.JMenuItem SaveAsFileMenuItem;
   private javax.swing.JMenuItem SaveFileMenuItem;
   private javax.swing.JButton TextoButton;
   private javax.swing.JMenuItem TraduzirMenuOption;
   private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
   private javax.swing.JMenu jMenu2;
   private javax.swing.JPanel jPanel2;
   private javax.swing.JPanel jPanel3;
   private javax.swing.JScrollPane jScrollPane2;
   private javax.swing.JSeparator jSeparator1;
   private javax.swing.JSeparator jSeparator2;
   private javax.swing.JSeparator jSeparator3;
   private javax.swing.JPopupMenu.Separator jSeparator4;
   private javax.swing.JTabbedPane mainTabbedPane;
   private javax.swing.JButton newOperadorButton;
   private javax.swing.JMenuItem novoArquivoB2C;
   private javax.swing.JMenu novoArquivoSubMenu;
   private javax.swing.JMenuItem novoOperador;
   private javax.swing.JPopupMenu popupMenuOperadores;
   private javax.swing.JTree tree;
   // End of variables declaration//GEN-END:variables

  //monta arvore de diretorios
  private void getList(DefaultMutableTreeNode node, File f) {
    if (!f.isDirectory()) {
      // We keep only JAVA source file for display in this HowTo
      if (f.getName().endsWith("java")) {
        //System.out.println("FILE  -  " + f.getName());
        DefaultMutableTreeNode child = new DefaultMutableTreeNode(f);
        node.add(child);
      }
    } else {
      //System.out.println("DIRECTORY  -  " + f.getName());
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(f);
      node.add(child);
      File fList[] = f.listFiles();
      for (int i = 0; i < fList.length; i++) {
        getList(child, fList[i]);
      }
    }
  }

  public final void popupMenuOperadores() {
    popupMenuOperadores.removeAll();
    
    JMenuItem item1 = new JMenuItem("Novo Operador");
    item1.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent e) {
        new newOperatorGuide().setVisible(true);
      }
    });
    popupMenuOperadores.add(item1);
    popupMenuOperadores.add(new Separator());

    /*TESTE*/
    ArrayList<Op_GenericoData> op_genericodata = Action.getInstance().getOp_generico();
    for (int i = 0; i < op_genericodata.size(); i++) {
      final Op_GenericoData op_g = op_genericodata.get(i);
      JMenuItem item2 = new JMenuItem(op_g.getNomeArquivo());
      item2.addActionListener(
              new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                  act.setOpAux(new Op_Generico(op_g));
                  estado = Estado.OPERADORES;
                }
              });
      popupMenuOperadores.add(item2);
    }
  }


  /*
   *
   * Enum de Estados do software
   *
   */
  public enum Estado {

    OPERADORES,
    CONECTORES_LINHA_RETA,
    CONECTORES_MAO_LIVRE,
    TEXTO,
    MOVER,
    ROTACAO,
    APAGAR,
    NULL;//Constante null
  }
}
